Ext.namespace('Ext.ux.grid');


Ext.ux.grid.RESTGrid = Ext.extend(Ext.grid.EditorGridPanel, {
	/*
	 * Search Text
	 */
	// Search Texts
 	  searchText : "Buscar"
	, searchTipText : "Buscar en la lista de items"
	, selectAllText : "Todos"

	, initComponent:function(config) {
		console.log("Iniciando RESTGrid");
		// Create Texts
		this.createText = "Agregar";
		this.createTipText = "Agregar nuevo item";

		this.resourceURL = this.resourceURL;
		this.ds = new Ext.data.GroupingStore({
			proxy : new Ext.data.HttpProxy({url : this.resourceURL, method : 'get'})
			, reader : this.reader
			, sortInfo : { field : 'name', direction : "ASC" }
		});
		this.sm = new Ext.grid.RowSelectionModel({ singleSelect : true });

		// Top Bar
//		this.tbar = ['->', {
//			text : this.createText
//			, tooltip : this.createTipText
//			, iconCls : 'icon-add'
//			, listeners:{
//						click:{scope:this, buffer:200, fn:function(btn) {
//							this.creating = true;
//							this.recordForm.title = this.createText;
//							this.recordForm.show(this.addRecord(), btn.getEl());
//						}}
//					}
		}];

		// Record Form
//		this.recordForm = new Ext.ux.grid.RecordForm({
//			  title : this.createText
//			, iconCls : 'icon-edit-record'
//			, columnCount : 2
//			, ignoreFields : {
//					action1 : true
//				}
//			, formConfig : {
//				  	  labelWidth : 80
//					, buttonAlign : 'right'
//					, bodyStyle : 'padding-top:10px'
//				}
//		});
		// Plugins
		this.plugins = [new Ext.ux.grid.Search({
			  mode : 'local'
			, iconCls : false
			, dateFormat : 'm/d/Y'
			, readonlyIndexes : []
			, disableIndexes : []
			, minLength : 2
			, position : 'top'
			, width: 200
			, searchText : this.searchText
			, searchTipText : this.searchTipText
			, selectAllText : this.selectAllText
		})];
		Ext.ux.grid.RESTGrid.superclass.initComponent.apply(this, config);
	} // eo function initComponent

	, addRecord : function() {
		var store = this.store;
		if(store.recordType) {
			var rec = new store.recordType({newRecord:true});
			rec.fields.each(function(f) {
				rec.data[f.name] = f.defaultValue || null;
			});
			rec.commit();
			store.insert(0, rec);
			return rec;
		}
		return false;
	}
});